package com.colin.app.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.colin.app.R;
import com.colin.app.bean.ItemBean;
import com.colin.library.adapter.BaseRecyclerAdapter;
import com.colin.library.adapter.BaseViewHolder;
import com.colin.library.base.BaseFragment;
import com.colin.library.help.ImageLoader;

import java.util.List;


public class ItemBeanRecyclerViewAdapter extends BaseRecyclerAdapter<ItemBean> {
    private final int fragment_id;
    private final BaseFragment.OnFragmentListener onFragmentListener;

    public ItemBeanRecyclerViewAdapter(Context context, List<ItemBean> itemBeanList, int fragment_id, BaseFragment.OnFragmentListener onFragmentListener) {
        super(context, itemBeanList, R.layout.item_itembean_list);
        this.fragment_id = fragment_id;
        this.onFragmentListener = onFragmentListener;
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
//        if (fragment_id == Constants.FRAGMENT_RECYCLER_VIEW_TYPE_STAGGERED) {
//            CardView.LayoutParams layoutParams = (CardView.LayoutParams) holder.itemView.getLayoutParams();
//            layoutParams.height = (position % 2 + 1) * layoutParams.height;
//            holder.itemView.setLayoutParams(layoutParams);
//        }
        super.onBindViewHolder(holder, position);
    }

    @Override
    protected void convert(BaseViewHolder holder, final ItemBean item) {
        ImageLoader.getInstance().loadImageByGlide((ImageView) holder.getView(R.id.image_itembean_background), item.getImageLarge());
        holder.setText(R.id.text_itembean_title, item.getTitle());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != onFragmentListener) {
                    onFragmentListener.onFragmentClick(fragment_id, true, 0, item);
                }
            }
        });
        holder.getView(R.id.text_itembean_title).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != onFragmentListener) {
                    onFragmentListener.onFragmentClick(fragment_id, true, 1, item);
                }
            }
        });
    }


}
